//
//  BaseTableViewController.m
//  XM
//
//  Created by mingyue on 2017/12/21.
//  Copyright © 2017年 mingyue. All rights reserved.
//

#import "BaseTableViewController.h"

@interface BaseTableViewController ()<UITableViewDelegate, UITableViewDataSource>

@end

@implementation BaseTableViewController

- (NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [NSMutableArray new];
    }
    return _dataArray;
}
- (UITableView *)tableView {
    if(!_tableView){
        UITableView *tab = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
        tab.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, CGFLOAT_MIN)];
        [self.view addSubview:tab];
        _tableView = tab;
        tab.dataSource = self;
        tab.delegate = self;
        tab.backgroundColor = [UIColor colorWithRed:0.94f green:0.94f blue:0.94f alpha:1.00f];
        tab.separatorColor= kSeperatorColor;
        tab.showsVerticalScrollIndicator = NO;
        tab.showsHorizontalScrollIndicator = NO;
        tab.estimatedRowHeight = 0;
        tab.estimatedSectionHeaderHeight = 0;
        tab.estimatedSectionFooterHeight = 0;
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kSeperatorColor;
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }
}

-(void)setUpTableViewWithStyle:(UITableViewStyle )style
{
    CGRect rect = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64);
    UITableView *tab = [[UITableView alloc] initWithFrame:rect style:style];
    [self.view addSubview:tab];
    _tableView = tab;
    tab.dataSource = self;
    tab.delegate = self;
    tab.backgroundColor = [UIColor colorWithRed:0.94f green:0.94f blue:0.94f alpha:1.00f];
    tab.separatorColor= kSeperatorColor;
    tab.showsVerticalScrollIndicator = NO;
    tab.showsHorizontalScrollIndicator = NO;
    tab.estimatedRowHeight = 0;
    tab.estimatedSectionHeaderHeight = 0;
    tab.estimatedSectionFooterHeight = 0;
    
}

-(void)addMJrefreshWithHeader:(BOOL)isHead andFooter:(BOOL)isFoot
{
    __weak  typeof(&*self) weakSelf = self;
    if (isHead) {
        // 允许添加 上啦刷新
        MJRefreshNormalHeader *header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
            [weakSelf tableVIewHeaderViewRefresh];
        }];
        //        // 隐藏时间
        //        header.lastUpdatedTimeLabel.hidden = YES;
        //        // 隐藏状态
        //        header.stateLabel.hidden = YES;
        self.tableView.mj_header = header;
    }
    if (isFoot) {
        MJRefreshAutoNormalFooter * footer  = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
            [weakSelf tableViewFooterViewRefresh];
        }];
        
        self.tableView.mj_footer = footer;
        
        //        [footer setTitle:@"—————— 上拉有惊喜 ——————" forState:MJRefreshStateIdle];
        //        [footer setTitle:@"努力加载中..." forState:MJRefreshStateRefreshing];
        [footer setTitle:@"" forState:MJRefreshStateNoMoreData];
    }
    //    // 一旦 添加到视图上面的时候 就开始 加载数据
    //    [self.tableView.mj_header beginRefreshing];
}

-(void)tableVIewHeaderViewRefresh
{
    
}

-(void)tableViewFooterViewRefresh
{
}


@end


